﻿using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using Shine.Framework;

using SuperMap.UI;
using SuperMap.Data;
using SuperMap.Realspace;
using System.Diagnostics;
using System;

namespace Shine.Viewer
{
    internal class PersonViewer:BaseCommand
    {
        IApplication m_Application = null;
        
        public PersonViewer()
        {
            base.m_caption = "人行视角";
            base.m_name = "PersonViewer";
            base.m_toolTip = "人行视角";
            base.m_message = "人行视角";
            base.m_category = "Viewer";
        }

        public override void OnCreate(object hook)
        {
            if (m_Application == null)
            {
                m_Application = hook as IApplication;
            }
        }

        public override void OnClick()
        {
            try
            {
                // 获取当前场景的中心点
                Camera ca = (m_Application as IFramework).SceneControl.Scene.Camera;
                double altitude = 3.0;
                double tile = 45;
                ca.Altitude = altitude;
                ca.Tilt = tile;
                ca.AltitudeMode = AltitudeMode.RelativeToGround;
                (m_Application as IFramework).SceneControl.Scene.Camera = ca;
                (m_Application as IFramework).SceneControl.Scene.Refresh();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex.Message);
            }
        }

        public override bool Checked
        {
            get
            {
                return base.Checked;
            }
        }


        public override int Bitmap
        {
            get
            {
                string imgFile = Application.StartupPath + "\\Images\\" + GetType().Name + ".png";

                if (System.IO.File.Exists(imgFile) == false) return 0;

                return new Bitmap(Image.FromFile(imgFile)).GetHbitmap().ToInt32();
            }
        }

        public override bool Enabled
        {
            get
            {
                return
                    (m_Application as IFramework).SceneControl.Scene != null;
            }
        }
    }
}
